package org.bot.client.config;

import org.bot.api.config.ClientConfig;
import org.bot.client.flow.FlowExecute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

//@Component
public class BotConfig {

    static Logger logger = LoggerFactory.getLogger(FlowExecute.class);

    public BotConfig() {
        FileInputStream in = null;
        try {
            in = new FileInputStream(System.getProperty("user.dir") + "/config/bot-config.properties");
        } catch (FileNotFoundException e) {
            logger.error("读取配置异常:", e);
        }
        if (in == null) {
            throw new RuntimeException("配置文件读取错误");
        }
        Properties properties = new Properties();
        try {
            properties.load(in);
            ClientConfig.buildClientConfig(properties);
        } catch (IOException e) {
            logger.error("读取配置异常:", e);
        }
    }


    public ClientConfig getClientConfig() {
        return ClientConfig.getBotConfig();
    }

}
